package abhiWeb.com.abhi.service.common;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;


public class ConnectionManager {
	
	public static Connection getConnection() throws Exception {
		String dataSourceName = "abhiuser";
		return getConnection(dataSourceName);
	}

	public static Connection getConnection(Object optional) throws Exception {
		Connection con = null;

		String dataSourceName = (String) optional;

		try {
			Context initContext = new InitialContext();
			Context envContext  = (Context)initContext.lookup("java:/comp/env");
			DataSource ds = (DataSource)envContext.lookup("jdbc/abhiuser");
			con = ds.getConnection();
		} catch (SQLException sqlException) {
			throw sqlException;
		} catch (NamingException namingException) {
			throw namingException;
		}
		return con;
	}
	
	
	
}
